<?php

/**
 * 排名相关
 */
class rankModel extends paomeBaseModel
{

    public function __construct(& $base)
    {
        parent::__construct($base);

        $this->table = 'r_pm_rank';
        $this->desc = array(
            'RANK1'=>"比昨日↑%s",
            'RANK2'=>"比昨日↓%s",
            'RANK3'=>"持平"
        );
    }

    /**
     * 查询赛季排行列表
     */
    public function getRankList(array $params) {
        $start     = $params['start'] ? (int)$params['start'] : 0;
        $limitNum  = $params['limit'] ? (int)$params['limit'] : 10;
        $paomeId = $params['paomeId'];
        $roundId = isset($params['contestStatus']) ? (int)$params['contestStatus'] : 1;
        $title     = isset($params['name']) ? trim($params['name']) : '';//俱乐部昵称
        $typeWd    = isset($params['typeWd']) ? (int)$params['typeWd'] : 1; //1;排名维度:1 总里程 5 配速 10 人气 15 全员跑量榜
        $this->total = 0;
        $result = [];
        if ($title) {
            if ($typeWd == 1) {
                $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                if ($this->redis->zCard($rankClubKeyMile)) {
                    $list = $this->redis->zRevRange($rankClubKeyMile,0,-1);
                }
            } else if ($typeWd == 5){
                $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;
                if ($this->redis->zCard($rankClubKeySpeed)) {
                    $list = $this->redis->zRange($rankClubKeySpeed,0,-1);
                }
            } else if ($typeWd == 10){
                $rankClubKeySupportNum = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;
                if ($this->redis->zCard($rankClubKeySupportNum)) {
                    $list = $this->redis->zRevRange($rankClubKeySupportNum,0,-1);
                }
            } else if ($typeWd == 15){
                $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
                if ($this->redis->zCard($rankUserKeyMile)) {
                    $list = $this->redis->zRevRange($rankUserKeyMile,0,-1);
                }
            } else {
                $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                if ($this->redis->zCard($rankClubKeyMile)) {
                    $list = $this->redis->zRevRange($rankClubKeyMile,0,-1);
                }
            }
            if (!$list) {
                return $result;
            }
            if (in_array($typeWd,array(1,5,10))) {
                $strClubId = implode(',',$list);
                $result = $this->paomeDb->getAll("select id, title,image from  r_pm_club where id in($strClubId) and title like '%$title%' and status=0 limit $start,$limitNum");
                $this->total = $this->paomeDb->getOne("select count(1) from  r_pm_club where id in($strClubId) and title like '%$title%'");
            } else if ($typeWd == 15) {
                $strUserId = implode(',',$list);
                //俱乐部ID
                $arrClubList = $this->paomeDb->getAll("select id, title from  r_pm_club where  title like '%$title%' and status=0");
                if (!$arrClubList) return [];
                $arrOneCid = [];
                foreach ($arrClubList as $k2=>$v2) {
                    $arrOneCid[] = $v2['id'];
                }
                $strClubId = implode(',',$arrOneCid);
                $result = $this->paomeDb->getAll("select uid,club_id from  r_pm_club_users where id in($strUserId) and club_id in($strClubId) limit $start,$limitNum");
                $this->total = $this->paomeDb->getOne("select count(1) from  r_pm_club_users where id in($strUserId) and club_id in($strClubId) and status=0");
            }

            if (!$this->total) return [];
            foreach ($result as $key=>$val) {//填充页面所需字段
                if ($typeWd == 1) {
                    $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeyMile,$val['id']) !== false) ? ($this->redis->zRevRank($rankClubKeyMile,$val['id'])+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeyMile,$val['id']);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $result[$key]['clubName'] = $val['title'];;
                    $result[$key]['clubImage'] = $val['image'];
                } else if ($typeWd == 5){
                    $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRank($rankClubKeySpeed,$val['id']) !==false) ? ($this->redis->zRank($rankClubKeySpeed,$val['id'])+1) :'';
                    $rankValue = ($this->redis->zScore($rankClubKeySpeed,$val['id']) !==false) ? common::sec3format($this->redis->zScore($rankClubKeySpeed,$val['id'])) : common::sec3format(0);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $result[$key]['clubName'] = $val['title'];;
                    $result[$key]['clubImage'] = $val['image'];
                } else if ($typeWd == 10){
                    $rankClubKeySupportNum = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeySupportNum,$val['id']) !==false) ? ($this->redis->zRevRank($rankClubKeySupportNum,$val['id'])+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeySupportNum,$val['id']);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $result[$key]['clubName'] = $val['title'];
                    $result[$key]['clubImage'] = $val['image'];
                } else if ($typeWd == 15){
                    $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankUserKeyMile,$val['uid']) !==false) ? ($this->redis->zRevRank($rankUserKeyMile,$val['uid'])+1) :'';
                    $rankValue = $this->redis->zScore($rankUserKeyMile,$val['uid']);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubInfo = $this->paomeDb->getRow("select title,image from r_pm_club where id={$val['club_id']}");
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title']  : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                    $result[$key]['uid'] = $val['uid'];
                    $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'],'header');
                    $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'],'nickname');
                    $result[$key]['userHeader'] = $header;
                    $result[$key]['userNickName'] = $nickname;
                } else {
                    $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeyMile,$val['id']) !==false) ? ($this->redis->zRevRank($rankClubKeyMile,$val['id'])+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeyMile,$val['id']);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $result[$key]['clubName'] = $val['title'];;
                    $result[$key]['clubImage'] = $val['image'];
                }
            }
        } else {
            if ($typeWd == 1) {
                $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                if ($total = $this->redis->zCard($rankClubKeyMile)) {
                    $list = $this->redis->zRevRange($rankClubKeyMile,$start,$limitNum);
                }
            } else if ($typeWd == 5){
                $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;
                if ($total = $this->redis->zCard($rankClubKeySpeed)) {
                    $list = $this->redis->zRange($rankClubKeySpeed,$start,$limitNum);
                }
            } else if ($typeWd == 10){
                $rankClubKeySupportNum = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;
                if ($total = $this->redis->zCard($rankClubKeySupportNum)) {
                    $list = $this->redis->zRevRange($rankClubKeySupportNum,$start,$limitNum);
                }
            } else if ($typeWd == 15){
                $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
                if ($total = $this->redis->zCard($rankUserKeyMile)) {
                    $list = $this->redis->zRevRange($rankUserKeyMile,$start,$limitNum);
                }
            } else {
                $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                if ($total = $this->redis->zCard($rankClubKeyMile)) {
                    $list = $this->redis->zRevRange($rankClubKeyMile,$start,$limitNum);
                }
            }
            if (!$total) {
                return [];
            }
            $this->total = $total;
            foreach ($list as $key=>$val) {//填充页面所需字段
                if ($typeWd == 1) {
                    $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeyMile,$val) !==false) ? ($this->redis->zRevRank($rankClubKeyMile,$val)+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeyMile,$val);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubInfo = $this->paomeDb->getRow("select id,title,image from r_pm_club where id=$val");
                    $result[$key]['id'] = $clubInfo ? $clubInfo['id'] : 0;
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title'] : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                } else if ($typeWd == 5){
                    $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRank($rankClubKeySpeed,$val) !==false) ? ($this->redis->zRank($rankClubKeySpeed,$val)+1) :'';
                    $rankValue =($this->redis->zScore($rankClubKeySpeed,$val)!==false) ? common::sec3format($this->redis->zScore($rankClubKeySpeed,$val)) : common::sec3format(0);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubInfo = $this->paomeDb->getRow("select id,title,image from r_pm_club where id=$val");
                    $result[$key]['id'] = $clubInfo ? $clubInfo['id'] : 0;
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title'] : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                } else if ($typeWd == 10){
                    $rankClubKeySupportNum = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeySupportNum,$val) !==false) ? ($this->redis->zRevRank($rankClubKeySupportNum,$val)+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeySupportNum,$val);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubInfo = $this->paomeDb->getRow("select id,title,image from r_pm_club where id=$val");
                    $result[$key]['id'] = $clubInfo ? $clubInfo['id'] : 0;
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title'] : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                } else if ($typeWd == 15){
                    $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankUserKeyMile,$val) !==false) ? ($this->redis->zRevRank($rankUserKeyMile,$val)+1) :'';
                    $rankValue = $this->redis->zScore($rankUserKeyMile,$val);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubId = $this->paomeDb->getOne("select club_id from r_pm_club_users where uid= $val and status=0");
                    $clubInfo = [];
                    if ($clubId) {
                        $clubInfo = $this->paomeDb->getRow("select title,image from r_pm_club where id=$clubId");
                    }
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title']  : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                    $result[$key]['uid'] = $val;
                    $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val,'header');
                    $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val,'nickname');
                    $result[$key]['userHeader'] = $header;
                    $result[$key]['userNickName'] = $nickname;
                } else {
                    $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;
                    $rankNum = ($this->redis->zRevRank($rankClubKeyMile,$val) !==false) ? ($this->redis->zRevRank($rankClubKeyMile,$val)+1) :'';
                    $rankValue = $this->redis->zScore($rankClubKeyMile,$val);
                    $result[$key]['rankNum'] = $rankNum;
                    $result[$key]['rankValue'] = $rankValue;
                    $clubInfo = $this->paomeDb->getRow("select id,title,image from r_pm_club where id=$val");
                    $result[$key]['clubName'] = $clubInfo ? $clubInfo['title'] : '';
                    $result[$key]['clubImage'] = $clubInfo ? $clubInfo['image'] : '';
                }
            }
        }
        return $result;
    }

    /**
     * 查询俱乐部跑量排名---跑量排名都不包含已淘汰的战队信息 ，请去淘汰表查询(轮次)
     * 争霸赛没有里程总排名的概念，请勿调用此方法,去调用天的排名
     */
    public function getClubRankNum($clubId,$paomeId,$roundId) {
        $rankClubKeyMile= 'rankClub-mileage-'.$paomeId.'-'.$roundId;//轮次
        $rankNum = $this->redis->zRevRank($rankClubKeyMile,$clubId);
        return ($rankNum === false) ? null : $rankNum+1;
    }

    /**
     * 查询俱乐部跑量排名--去除已有冠军争霸赛俱乐部(轮次)
     * 争霸赛没有里程总排名的概念，请勿调用此方法,去调用天的排名
     */
    public function getClubRankNumOk($clubId,$paomeId,$roundId) {
        $rankClubKeyMile= 'rankClub-mileageOk-'.$paomeId.'-'.$roundId;//轮次
        $rankNum = $this->redis->zRevRank($rankClubKeyMile,$clubId);
        return ($rankNum === false) ? null : $rankNum+1;
    }

    /**
     * 查询俱乐部配速排名(轮次)
     * 争霸赛没有配速总排名的概念，请勿调用此方法,去调用天的排名
     */
    public function getClubSpeedRankNum($clubId,$paomeId,$roundId) {
        $rankClubKeySpeed= 'rankClub-speed-'.$paomeId.'-'.$roundId;//轮次
        $rankNum = $this->redis->zRank($rankClubKeySpeed,$clubId);
        return ($rankNum === false) ? null : $rankNum+1;
    }

    /**
     * 查询俱乐部人气排名(轮次)
     * 争霸赛人气排名：按照新规产生,其他轮次暂时不变
     */
    public function getClubSupportRankNum($clubId,$paomeId,$roundId) {
        $rankClubKeySupport= 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;//轮次
        $rankNum = $this->redis->zRevRank($rankClubKeySupport,$clubId);
        return ($rankNum === false) ? null : $rankNum+1;
    }

    /**
     * 查询战队里程 (轮次)
     */
    public function getClubMileageRankValue($clubId, $paomeId, $roundId) {
        $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;//页面展示排名
        $rankValue = $this->redis->zScore($rankClubKeyMile,$clubId);
        return (double)$rankValue;
    }

    /**
     * 查询战队配速 （轮次）
     */
    public function getClubSpeedRankValue($clubId, $paomeId, $roundId) {
        $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;//页面展示排名
        $rankValue = $this->redis->zScore($rankClubKeySpeed,$clubId);
        return (int)$rankValue;
    }

    /**
     * 查询战队人气值  （轮次）
     */
    public function getClubSupportRankValue($clubId, $paomeId, $roundId) {
        $rankClubKeySupport = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;//页面展示排名
        $rankValue = $this->redis->zScore($rankClubKeySupport,$clubId);
        return (int)$rankValue;
    }

    /**
     * 查询战队天排名
     * 对于争霸赛来说是 跑量和配速是单独的每天值，其他还是跟以前一样
     * $params $objectId 1,5,10 战队ID 15：用户UID
     * $params $objectType 1:里程 5：配速 10：人气 15全员跑量榜
     */
    public function getObjectDayRank($objectId, $paomeId, $roundId, $date, $objectType=1) {
        $rankNum = false;
        switch($objectType) {
            case 1:
                if ($roundId == 100) {//争霸赛新规
                    $rankClubDayKeyMileNew = 'rankClubDay-mileageNew-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',strtotime($date));//天（争霸赛：用于查排名非score）
                    //初始化redis产生默认排名，先取值，判断是否是默认值，如果是默认值0，排名展示为--
                    $rankValue = $this->redis->zScore($rankClubDayKeyMileNew, $objectId);
                    if ($rankValue === false || ($rankValue==0)) {
                        $rankNum = false;
                    } else {
                        $rankNum = $this->redis->zRevRank($rankClubDayKeyMileNew, $objectId);
                    }
                } else {
                    $rankClubDayKeyMile = 'rankClubDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',strtotime($date));//天
                    $rankNum = $this->redis->zRevRank($rankClubDayKeyMile, $objectId);
                }
                break;
            case 5:
                if ($roundId == 100) {//争霸赛新规
                    $rankClubDayKeySpeedNew = 'rankClubDay-speedNew-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d', strtotime($date));//天(争霸赛：用于查排名非score)
                    //初始化redis产生默认排名，先取值，判断是否是默认值，如果是默认值10000，排名展示为--
                    $rankValue = $this->redis->zScore($rankClubDayKeySpeedNew, $objectId);
                    //大于5人才算排名
                    $dayRunUserNum = $this->base->load('paome/cup')->getCurrentDayRunUserCnt($paomeId, $objectId, $date);
                    if ($rankValue === false || ($rankValue== cupModel::DEFAULT_SPEED_RANK_VALUE) || ($dayRunUserNum <cupModel::CLUB_SPEED_MIN_USER_NUM)) {//新规 >=5人，才算配速
                        $rankNum = false;
                    } else {
                        $rankNum = $this->redis->zRank($rankClubDayKeySpeedNew, $objectId);
                    }
                } else {
                    $rankClubDayKeySpeed = 'rankClubDay-speed-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',strtotime($date));//天(争霸赛：用于查score非排名)
                    $rankNum = $this->redis->zRank($rankClubDayKeySpeed, $objectId);
                }
                break;
            case 10:
                $rankClubDayKeySupportNum = 'rankClubDay-supportNum-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d', strtotime($date));//天
                if ($roundId == 100) {//争霸赛新规
                    //初始化redis产生默认排名，先取值，判断是否是默认值，如果是默认值0，排名展示为--
                    $rankValue = $this->redis->zScore($rankClubDayKeySupportNum, $objectId);
                    if ($rankValue === false || ($rankValue==0)) {
                        $rankNum = false;
                    } else {
                        $rankNum = $this->redis->zRevRank($rankClubDayKeySupportNum, $objectId);
                    }
                } else {
                    $rankNum = $this->redis->zRevRank($rankClubDayKeySupportNum, $objectId);
                }
                break;
            case 15: //唯一一个没有初始化的维度
                $rankUserDayKeyMile = 'rankUserDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',strtotime($date));//天
                $rankValue = $this->redis->zScore($rankUserDayKeyMile, $objectId);
                if ($rankValue === false || ($rankValue==0)) {
                    $rankNum = false;
                } else {
                    $rankNum = $this->redis->zRevRank($rankUserDayKeyMile, $objectId);
                }
                break;
        }
        return ($rankNum === false) ? null : $rankNum+1;
    }

    /**
     * 查询战队天维度值
     * 对于争霸赛来说是 跑量和配速是单独的每天值，其他还是跟以前一样
     * $params $objectId 1,5,10 战队ID 15：用户UID
     * $params $objectType 1:里程 5：配速 10：人气 15全员跑量榜
     */
    public function getObjectDayRankValue($objectId, $paomeId, $roundId, $date, $objectType=1,$speedWd = 1) {
        $rankValue = 0;
        switch($objectType) {
            case 1:
                $rankClubDayKeyMile = 'rankClubDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d', strtotime($date));//天（争霸赛：用于查socre非排名）
                $rankValue = $this->redis->zScore($rankClubDayKeyMile, $objectId);
                break;
            case 5:
                $rankClubDayKeySpeed = 'rankClubDay-speed-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d', strtotime($date));//天(争霸赛：用于查score非排名)
                $rankValue = $this->redis->zScore($rankClubDayKeySpeed, $objectId);
                //大于5人战队才算排名
                $dayRunUserNum = $this->base->load('paome/cup')->getCurrentDayRunUserCnt($paomeId, $objectId, $date);
                if ($rankValue == cupModel::DEFAULT_SPEED_RANK_VALUE || ($rankValue === false) ||($dayRunUserNum < cupModel::CLUB_SPEED_MIN_USER_NUM)) {//预设默认值
                    $rankValue = 0;
                }
                $rankValue = ($speedWd ==1) ? common::sec3format($rankValue): $rankValue;//格式化
                break;
            case 10:
                $rankClubDayKeySupportNum = 'rankClubDay-supportNum-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d', strtotime($date));//天
                $rankValue = $this->redis->zScore($rankClubDayKeySupportNum, $objectId);
                break;
            case 15:
                $rankUserDayKeyMile = 'rankUserDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',strtotime($date));//天
                $rankValue = $this->redis->zScore($rankUserDayKeyMile, $objectId);
                break;
        }
        return ($rankValue === false) ? 0 : $rankValue;
    }


    /**
     * 俱乐部是否取得过争霸赛资格
     */
    public function getClubIsHaveTicket($paomeId, $clubId) {
        $bool = false;
        foreach(array(1,5,10) as $key=>$val) {
            $rankClubKeyMileZbsTicket = 'rankClub-mileageZbs-ticker-'.$paomeId.'-'.$val;//第一轮冠军不参与第二轮晋级争霸赛排名，决赛计算用到
            $haveTopTicket = $this->redis->hGet($rankClubKeyMileZbsTicket,$clubId);
            if ($haveTopTicket === false) {
                $topTicketId = $this->paomeDb->getOne("select id from r_pm_champions_member where contest_id=$paomeId and club_id=$clubId and round_type=$val");
                if (!$topTicketId) {
                    //增加非争霸赛资格redis记录，值为0
                    $rankClubKeyMileZbsTicket = 'rankClub-mileageZbs-ticker-'.$paomeId.'-'.$val;//第一轮冠军不参与第二轮晋级争霸赛排名，决赛计算用到
                    $this->redis->hSet($rankClubKeyMileZbsTicket,$clubId,0);
                    $bool =  false;
                } else {
                    //增加争霸赛资格redis记录,值为1
                    $rankClubKeyMileZbsTicket = 'rankClub-mileageZbs-ticker-'.$paomeId.'-'.$val;//第一轮冠军不参与第二轮晋级争霸赛排名，决赛计算用到
                    $this->redis->hSet($rankClubKeyMileZbsTicket,$clubId,1);
                    $bool =  true;
                    break;
                }

            } else if ($haveTopTicket == 1) {
                $bool =  true;
                break;
            } else {
                $bool =  false;
            }
        }
        return $bool;
    }

    /**
     * H5查询排名
     * @param $paomeId
     * @param $roundId 轮次
     * @param $typeWd   维度 1 总里程 5 配速 10 人气 15 全员跑量榜
     * @param $uid
     * @param $clubName
     */
    public function getRankForH5($paomeId, $roundId=1, $typeWd=1, $uid=0, $clubName=null,$page=1,$limit=20) {
        $result = array('topRankInfo'=>[],'list'=>[],'overRankList'=>[]);
        $start = ($page-1)*$limit;
        $end = $start+($limit-1);
        $this->total = 0;
        switch($typeWd) {
            case 1:
                $rankClubKeyMile = 'rankClub-mileage-'.$paomeId.'-'.$roundId;//轮次redis key
                /*置顶信息*/
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前战队
                    if ($arrCurrentClubinfo) {
                        $currentRank = ($this->redis->zRevRank($rankClubKeyMile, $arrCurrentClubinfo['id']) !== false) ? $this->redis->zRevRank($rankClubKeyMile, $arrCurrentClubinfo['id'])+1: false;
                        if ($currentRank) { //当前已参与,群主排行置顶
                            $currentRankValue = $this->redis->zScore($rankClubKeyMile, $arrCurrentClubinfo['id']);
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] =  $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                            $topRankInfo['overDesc'] = '';//淘汰标识文字
                            //名次变动说明文字数组
                            $topRankInfo['rankChangeInfo'] = $this->getObjectRankChange($paomeId, $roundId, $arrCurrentClubinfo['id'], 1);
                            $result['topRankInfo'] = $topRankInfo;
                        } else {
                            $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrCurrentClubinfo['id'], $roundId);//查询是否是正常参与 淘汰的
                            if ($arr) {
                                $currentRank = $arr['history_rank'];
                                $currentRankValue = $arr['mileage'];
                                $topRankInfo = [];
                                $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                                $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                                $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                                $topRankInfo['rank'] = ($currentRank!==false) ? $currentRank : '';
                                $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                                //名次变动说明文字数组
                                $topRankInfo['rankChangeInfo'] = [];
                                $topRankInfo['overDesc'] = '止步预选赛';//淘汰标识文字
                                $result['topRankInfo'] = $topRankInfo;
                            }
                        }
                    }
                }
                $this->total = $this->redis->zCard($rankClubKeyMile);
                //if(!$this->total) return $result;
                $temp = [];
                if (!$clubName) {
                    $list = $this->redis->zRevRange($rankClubKeyMile,0, -1);
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val,'title,image');
                        $rankValue = $this->redis->zScore($rankClubKeyMile,$val);
                        $temp[$key]['clubId'] = $val;
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $key+1;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['overDesc'] = '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $this->getObjectRankChange($paomeId, $roundId, $val, 1);
                    }
                    $result['list'] = $temp;
                } else {
                    //查询所有的俱乐部ID
                    $arrClubId = $this->redis->zRevRange($rankClubKeyMile,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    //$list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%' limit $start,$limit");
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['clubId'],'title,image');
                        $rank = $this->redis->zRevRank($rankClubKeyMile,$val['clubId']);
                        $rankValue = $this->redis->zScore($rankClubKeyMile,$val['clubId']);
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';

                        $temp[$key]['rank'] = ($rank !== false) ? $rank+1 : 0;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['overDesc'] = '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $this->getObjectRankChange($paomeId, $roundId, $val['clubId'], 1);
                    }
                    $result['list'] = $temp;
                }
                //淘汰的俱乐部
                $result['overRankList'] = $this->getRankOverClub($paomeId, $roundId);
                break;
            case 5:
                $rankClubKeySpeed = 'rankClub-speed-'.$paomeId.'-'.$roundId;
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前群主
                    if ($arrCurrentClubinfo) {//当前已参与,群主排行置顶
                        $currentRank = ($this->redis->zRank($rankClubKeySpeed, $arrCurrentClubinfo['id']) !== false) ?  $this->redis->zRank($rankClubKeySpeed, $arrCurrentClubinfo['id'])+1 : false;
                        if ($currentRank) {
                            $currentRankValue = $this->redis->zScore($rankClubKeySpeed, $arrCurrentClubinfo['id']);
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] = $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? common::sec3format($currentRankValue) : common::sec3format(0);
                            $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrCurrentClubinfo['id'], $roundId);//查询是否是正常参与 淘汰的
                            $topRankInfo['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                            //名次变动说明文字数组
                            $topRankInfo['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $arrCurrentClubinfo['id'], 5);
                            $result['topRankInfo'] = $topRankInfo;
                        }
                    }
                }
                $this->total = $this->redis->zCard($rankClubKeySpeed);
                if(!$this->total) return $result;
                $temp = [];
                if (!$clubName) {
                    $list = $this->redis->zRange($rankClubKeySpeed,0, -1);
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val,'title,image');
                        $rankValue = $this->redis->zScore($rankClubKeySpeed,$val);
                        $temp[$key]['clubId'] = $val;
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $key+1;
                        $temp[$key]['rankValue'] = $rankValue !==false ? common::sec3format($rankValue): common::sec3format(0);
                        $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $val, $roundId);//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val, 5);
                    }
                } else {
                    //查询所有的俱乐部ID
                    $arrClubId = $this->redis->zRevRange($rankClubKeySpeed,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    //$list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%' limit $start,$limit");
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] =$val['clubName'];
                        $temp[$key]['image'] = $val['image'];
                        $rankValue = $this->redis->zScore($rankClubKeySpeed,$val['clubId']);
                        $rank = $this->redis->zRank($rankClubKeySpeed,$val['clubId']);
                        $temp[$key]['rank'] = ($rank !== false) ? $rank+1 :0;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? common::sec3format($rankValue) : common::sec3format(0);
                        $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $val['clubId'], $roundId);//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val['clubId'], 5);
                    }
                }
                $result['list'] = $temp;
                break;
            case 10:
                $rankClubKeySupportNum = 'rankCLub-supportNum-'.$paomeId.'-'.$roundId;
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前群主
                    if ($arrCurrentClubinfo) {//当前已参与,群主排行置顶
                        $currentRank = ($this->redis->zRevRank($rankClubKeySupportNum, $arrCurrentClubinfo['id']) !== false) ? $this->redis->zRevRank($rankClubKeySupportNum, $arrCurrentClubinfo['id'])+1 : false;
                        if ($currentRank) {
                            $currentRankValue = $this->redis->zScore($rankClubKeySupportNum, $arrCurrentClubinfo['id']);
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] = $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                            $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrCurrentClubinfo['id'], $roundId);//查询是否是正常参与 淘汰的
                            $topRankInfo['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                            //名次变动说明文字数组
                            $topRankInfo['rankChangeInfo'] =$arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $arrCurrentClubinfo['id'], 10);
                            $result['topRankInfo'] = $topRankInfo;
                        }

                    }
                }
                $this->total = $this->redis->zCard($rankClubKeySupportNum);
                if(!$this->total) return $result;
                $temp =[];
                if (!$clubName) {
                    $list = $this->redis->zRevRange($rankClubKeySupportNum,0,-1);
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val,'title,image');
                        $rankValue = $this->redis->zScore($rankClubKeySupportNum,$val);
                        $temp[$key]['clubId'] = $val;
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $key+1;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $val, $roundId);//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val, 10);
                    }
                } else {
                    //查询所有的俱乐部ID
                    $arrClubId = $this->redis->zRevRange($rankClubKeySupportNum,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    //$list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%' limit $start,$limit");
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] = $val['clubName'];
                        $temp[$key]['image'] = $val['image'];
                        $rank = $this->redis->zRevRank($rankClubKeySupportNum,$val['clubId']);
                        $rankValue = $this->redis->zScore($rankClubKeySupportNum,$val['clubId']);
                        $temp[$key]['rank'] = ($rank !==false) ? $rank+1 : 0;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $val['clubId'], $roundId);//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val['clubId'], 10);
                    }
                }
                $result['list'] = $temp;
                break;
            case 15:
                $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前群主
                    if ($arrCurrentClubinfo) {//当前已参与,群主排行置顶
                        $currentRank = ($this->redis->zRevRank($rankUserKeyMile, $uid) !== false) ? $currentRank = $this->redis->zRevRank($rankUserKeyMile, $uid)+1 : false;
                        if ($currentRank) {
                            $currentRankValue = $this->redis->zScore($rankUserKeyMile, $uid);
                            $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $uid,'header');
                            $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $uid,'nickname');
                            $topRankInfo = [];
                            $topRankInfo['uid'] = $uid;
                            $topRankInfo['userName'] = $nickname;
                            $topRankInfo['header'] = $header;
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] = $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                            $arr = $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrCurrentClubinfo['id'], $roundId);//查询是否是正常参与 淘汰的
                            $topRankInfo['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                            //名次变动说明文字数组
                            $topRankInfo['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $uid, 15);
                            $result['topRankInfo'] =$topRankInfo;
                        }
                    }
                }
                $this->total = $this->redis->zCard($rankUserKeyMile);
                if(!$this->total) return $result;
                $temp = [];
                if (!$clubName) {
                    $list = $this->redis->zRevRange($rankUserKeyMile,0,100);
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($val,'id,title,image');
                        $rankValue = $this->redis->zScore($rankUserKeyMile,$val);
                        $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val,'header');
                        $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val,'nickname');
                        $temp[$key]['uid'] = $val;
                        $temp[$key]['userName'] = $nickname;
                        $temp[$key]['header'] = $header;
                        $temp[$key]['clubId'] = $arrClubInfo ? $arrClubInfo['id'] : '';
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $key+1;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $arr = $arrClubInfo ? $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrClubInfo['id'], $roundId) : [];//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val, 15) ;
                    }
                } else {
                    //查询所有的俱乐部ID
                    $arrTwoClubId = $this->paomeDb->getAll("select id from r_pm_club where title like '%$clubName%'");
                    if (!$arrTwoClubId) return $result;
                    //$arrClubId = array_column($arrTwoClubId, 'id');
                    $arrClubId = [];
                    foreach($arrTwoClubId as $kC=>$vC) {
                        $arrClubId[] = $vC['id'];
                    }
                    $strClubId = implode(',',$arrClubId);
                    $arrUid = $this->redis->zRevRange($rankUserKeyMile,0,-1);
                    $strUid = implode(',',$arrUid);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club_users where club_id in($strClubId) and uid in($strUid)");
                    if(!$this->total) return $result;
                    //$list = $this->paomeDb->getAll("select club_id,uid from r_pm_club_users where club_id in($strClubId) and uid in($strUid) limit $start,$limit");
                    $list = $this->paomeDb->getAll("select club_id,uid from r_pm_club_users where club_id in($strClubId) and uid in($strUid) limit 100");//暂取200条
                    foreach ($list as $key=>$val) {
                        $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'],'header');
                        $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'],'nickname');
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['club_id'],'id,title,image');
                        $rank = $this->redis->zRevRank($rankUserKeyMile,$val['uid']);
                        $rankValue = $this->redis->zScore($rankUserKeyMile,$val['uid']);
                        $temp[$key]['uid'] = $val['uid'];
                        $temp[$key]['userName'] = $nickname;
                        $temp[$key]['header'] = $header;
                        $temp[$key]['clubId'] = $val['club_id'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = ($rank !==false) ? $rank+1 : 0;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $arr = $arrClubInfo ? $this->base->load('paome/paomeClub')->getIsExistOverClub($paomeId, $arrClubInfo['id'], $roundId) : [];//查询是否是正常参与 淘汰的
                        $temp[$key]['overDesc'] = $arr ? '止步于预赛' : '';//淘汰标识文字
                        //名次变动说明文字数组
                        $temp[$key]['rankChangeInfo'] = $arr ? [] : $this->getObjectRankChange($paomeId, $roundId, $val, 15);
                    }
                }
                $result['list'] = $temp;
                break;
            default:
                return [];
            break;
        }
        return $result;
    }

    /**
     * H5查询排名
     * @param $paomeId
     * @param $roundId 轮次暂时只支持争霸赛
     * @param $typeWd   维度 1 总里程 5 配速 10 人气 20 全员跑量榜
     * @param $uid
     * @param $clubName
     */
    public function getRankForH5New($paomeId, $roundId=1, $typeWd=1, $uid=0, $clubName=null,$page=1,$limit=20) {
        $result = array('topRankInfo'=>[],'list'=>[]);
        $start = ($page-1)*$limit;
        $end = $start+($limit-1);
        $this->total = 0;
        $roundId = 100;//争霸赛
        //查询争霸日期
        $arrDate = $this->base->load('paome/cup')->getDateList($paomeId, $roundId);
        if (!$arrDate) {
            return $result;
        }
        //查询主框显示的日期
        $date = $this->base->load('paome/cup')->getLastDate($arrDate); //当前显示的格式化日期值
        $nowTime = strtotime($date);//当前显示的日期时间戳
        $arrNewDate = $this->base->load('paome/cup')->getChildDateList($arrDate);//子框循环日期
        switch($typeWd) {
            case 1:
            case 10:
                if($typeWd == 1){
                    $rankClubDayKeyObjectNew = 'rankClubDay-mileageNew-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天（争霸赛：用于查排名非score）
                } else {
                    $rankClubDayKeyObjectNew = 'rankClubDay-supportNum-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天
                }
            /*置顶信息*/
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前战队
                    if ($arrCurrentClubinfo) {
                        //查询战队是否取得过争霸赛资格
                        $haveTicket = $this->getClubIsHaveTicket($paomeId, $arrCurrentClubinfo['id']);
                        if($haveTicket) { //排行置顶
                            $currentRank = $this->getObjectDayRank($arrCurrentClubinfo['id'], $paomeId, $roundId, $date, $typeWd);
                            $currentRankValue = $this->getObjectDayRankValue($arrCurrentClubinfo['id'], $paomeId, $roundId, $date, $typeWd);
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] =  $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                            $topRankInfo['score'] = $this->getClubRankScore((int)$currentRank, $typeWd);//可获得积分
                            //childList
                            $childList = [];
                            if($arrNewDate) {
                                foreach ($arrNewDate as $kc=>$vc) {
                                    $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                    $childList[$kc]['rankNum'] = $this->getObjectDayRank($arrCurrentClubinfo['id'], $paomeId, $roundId, $vc, $typeWd);
                                    $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($arrCurrentClubinfo['id'], $paomeId, $roundId, $vc, $typeWd);//昨日跑量
                                    $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id={$arrCurrentClubinfo['id']} and object_id={$arrCurrentClubinfo['id']} and `date`='$vc' and `type`=$roundId and type_wd=$typeWd");
                                    $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                                }
                            }
                            $topRankInfo['childList'] = $childList;
                            $result['topRankInfo'] = $topRankInfo;
                        }
                    }
                }
                $this->total = $this->redis->zCard($rankClubDayKeyObjectNew);
                $temp = [];
                if (!$clubName) {
                    $list = $this->redis->zRevRange($rankClubDayKeyObjectNew,0, -1);
                    if(!$list) return $result;
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val,'title,image');
                        $rankNum   = $this->getObjectDayRank($val, $paomeId, $roundId, $date, $typeWd);
                        $rankValue = $this->getObjectDayRankValue($val, $paomeId, $roundId, $date, $typeWd);
                        $temp[$key]['clubId'] = $val;
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $rankNum;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['score'] = $this->getClubRankScore((int)$rankNum, $typeWd);//可获得积分
                        //childList
                        $childList = [];
                        if($arrNewDate) {
                            foreach ($arrNewDate as $kc=>$vc) {
                                $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                $childList[$kc]['rankNum'] = $this->getObjectDayRank($val, $paomeId, $roundId, $vc, $typeWd);
                                $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($val, $paomeId, $roundId, $vc, $typeWd);//昨日跑量
                                $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id=$val and object_id=$val and `date`='$vc' and `type`=$roundId and type_wd=$typeWd");
                                $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                            }
                        }
                        $temp[$key]['childList'] = $childList;
                    }
                    $result['list'] = $temp;
                } else {
                    //查询所有的俱乐部ID
                    $arrClubId = $this->redis->zRevRange($rankClubDayKeyObjectNew,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['clubId'],'title,image');
                        $rankNum   = $this->getObjectDayRank($val['clubId'], $paomeId, $roundId, $date, $typeWd);
                        $rankValue = $this->getObjectDayRankValue($val['clubId'], $paomeId, $roundId, $date, $typeWd);
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $rankNum;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['score'] = $this->getClubRankScore((int)$rankNum, $typeWd);//可获得积分
                        //childList
                        $childList = [];
                        if($arrNewDate) {
                            foreach ($arrNewDate as $kc=>$vc) {
                                $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                $childList[$kc]['rankNum'] = $this->getObjectDayRank($val['clubId'], $paomeId, $roundId, $vc, $typeWd);
                                $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($val['clubId'], $paomeId, $roundId, $vc, $typeWd);//昨日跑量
                                $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id={$val['clubId']} and object_id={$val['clubId']} and `date`='$vc' and `type`=$roundId and type_wd=$typeWd");
                                $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                            }
                        }
                        $temp[$key]['childList'] = $childList;
                    }
                    $result['list'] = $temp;
                }
                break;
            case 5:
                /*置顶信息*/
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前战队
                    if ($arrCurrentClubinfo) {
                        //查询战队是否取得过争霸赛资格
                        $haveTicket = $this->getClubIsHaveTicket($paomeId, $arrCurrentClubinfo['id']);
                        if($haveTicket) { //排行置顶
                            $currentRank = $this->getObjectDayRank($arrCurrentClubinfo['id'], $paomeId, $roundId, $date, 5);
                            $currentRankValue = $this->getObjectDayRankValue($arrCurrentClubinfo['id'], $paomeId, $roundId, $date, 5);
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] =  $currentRank;
                            $topRankInfo['rankValue'] = ($currentRankValue !==false) ? $currentRankValue : '';
                            $topRankInfo['score'] = $this->getClubRankScore((int)$currentRank, 5);//可获得积分
                            //childList
                            $childList = [];
                            if($arrNewDate) {
                                foreach ($arrNewDate as $kc=>$vc) {
                                    $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                    $childList[$kc]['rankNum'] = $this->getObjectDayRank($arrCurrentClubinfo['id'], $paomeId, $roundId, $vc, $typeWd);
                                    $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($arrCurrentClubinfo['id'], $paomeId, $roundId, $vc, $typeWd);//昨日跑量
                                    $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id={$arrCurrentClubinfo['id']} and object_id={$arrCurrentClubinfo['id']} and `date`='$vc' and `type`=$roundId and type_wd=$typeWd");
                                    $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                                }
                            }
                            $topRankInfo['childList'] = $childList;
                            $result['topRankInfo'] = $topRankInfo;
                        }
                    }
                }
                $rankClubDayKeySpeedNew = 'rankClubDay-speedNew-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天(争霸赛：用于查排名非score)
                $this->total = $this->redis->zCard($rankClubDayKeySpeedNew);
                $temp = [];
                if (!$clubName) {
                    $list = $this->redis->zRange($rankClubDayKeySpeedNew,0, -1);
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val,'title,image');
                        $rankNum   = $this->getObjectDayRank($val, $paomeId, $roundId, $date, 5);
                        $rankValue = $this->getObjectDayRankValue($val, $paomeId, $roundId, $date, 5);
                        $temp[$key]['clubId'] = $val;
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $rankNum;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['score'] = $this->getClubRankScore((int)$rankNum, 5);//可获得积分
                        //childList
                        $childList = [];
                        if($arrNewDate) {
                            foreach ($arrNewDate as $kc=>$vc) {
                                $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                $childList[$kc]['rankNum'] = $this->getObjectDayRank($val, $paomeId, $roundId, $vc, 5);
                                $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($val, $paomeId, $roundId, $vc, 5);//昨日跑量
                                $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id=$val and object_id=$val and `date`='$vc' and `type`=$roundId and type_wd=5");
                                $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                            }
                        }
                        $temp[$key]['childList'] = $childList;
                    }
                    $result['list'] = $temp;
                } else {
                    //查询所有的俱乐部ID
                    $arrClubId = $this->redis->zRange($rankClubDayKeySpeedNew,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['clubId'],'title,image');
                        $rankNum   = $this->getObjectDayRank($val['clubId'], $paomeId, $roundId, $date, 5);
                        $rankValue = $this->getObjectDayRankValue($val['clubId'], $paomeId, $roundId, $date, 5);
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $rankNum;
                        $temp[$key]['rankValue'] = ($rankValue !==false) ? $rankValue : '';
                        $temp[$key]['score'] = $this->getClubRankScore((int)$rankNum, 5);//可获得积分
                        //childList
                        $childList = [];
                        if($arrNewDate) {
                            foreach ($arrNewDate as $kc=>$vc) {
                                $childList[$kc]['date'] = date('m.d',strtotime($vc));
                                $childList[$kc]['rankNum'] = $this->getObjectDayRank($val['clubId'], $paomeId, $roundId, $vc, 5);
                                $childList[$kc]['rankValue'] = $this->getObjectDayRankValue($val['clubId'], $paomeId, $roundId, $vc, 5);//昨日跑量
                                $score = $this->paomeDb->getOne("select score from r_pm_rank_day where contest_id=$paomeId and club_id={$val['clubId']} and object_id={$val['clubId']} and `date`='$vc' and `type`=$roundId and type_wd=5");
                                $childList[$kc]['score'] = (int)$score;//昨日获得的积分
                            }
                        }
                        $temp[$key]['childList'] = $childList;
                    }
                    $result['list'] = $temp;
                }
                break;
            case 20:
                /*置顶信息*/
                if ($uid){
                    $arrCurrentClubinfo = $this->base->load('paome/paomeClub')->getUserCurrentClubInfo($uid,'id,title,image');//查询用户当前战队
                    if ($arrCurrentClubinfo) {
                        //查询战队是否取得过争霸赛资格
                        $haveTicket = $this->getClubIsHaveTicket($paomeId, $arrCurrentClubinfo['id']);
                        if($haveTicket) { //排行置顶
                            $info = $this->paomeDb->getRow("select id,score_rank_num,total_score,mileage_score,speed_score,support_score from r_pm_score where contest_id=$paomeId and club_id={$arrCurrentClubinfo['id']} and `type`=$roundId");
                            $topRankInfo = [];
                            $topRankInfo['clubId'] = $arrCurrentClubinfo['id'];
                            $topRankInfo['clubName'] =$arrCurrentClubinfo['title'];
                            $topRankInfo['image'] = $arrCurrentClubinfo['image'];
                            $topRankInfo['rank'] =  $info ? $info['score_rank_num'] : 0;
                            $topRankInfo['rankValue'] = $info ? $info['total_score'] : 0;
                            $topRankInfo['mileageScore'] =  $info ? $info['mileage_score'] : 0;
                            $topRankInfo['speedScore'] =  $info ? $info['speed_score'] : 0;
                            $topRankInfo['supportScore'] =  $info ? $info['support_score'] : 0;
                            $result['topRankInfo'] = $topRankInfo;
                        }
                    }
                }
                $this->total = $this->paomeDb->getOne("select count(1) from r_pm_score where contest_id=$paomeId and `type`=$roundId");
                $temp = [];
                if (!$clubName) {
                    $list = $this->paomeDb->getAll("select * from r_pm_score where contest_id=$paomeId and `type`=$roundId order by score_temp_rank_num asc");
                    foreach($list as $key =>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['club_id'],'title,image');
                        $temp[$key]['clubId'] = $val['club_id'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $temp[$key]['rank'] = $val['score_rank_num'];
                        $temp[$key]['rankValue'] = $val['total_score'];
                        $temp[$key]['mileageScore'] = $val['mileage_score'];
                        $temp[$key]['speedScore'] =  $val['speed_score'];
                        $temp[$key]['supportScore'] =  $val['support_score'];
                    }
                    $result['list'] = $temp;
                } else {
                    //查询争霸赛所有的俱乐部ID
                    $rankClubDayKeyObjectNew = 'rankClubDay-mileageNew-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天（争霸赛：用于查排名非score）
                    $arrClubId = $this->redis->zRevRange($rankClubDayKeyObjectNew,0,-1);
                    $strClubId = implode(',',$arrClubId);
                    $this->total = $this->paomeDb->getOne("select count(1) from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    if(!$this->total) return $result;
                    $list = $this->paomeDb->getAll("select id as clubId,title as clubName,image from r_pm_club where id in($strClubId) and title like '%$clubName%'");
                    foreach ($list as $key=>$val) {
                        $arrClubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['clubId'],'title,image');
                        $temp[$key]['clubId'] = $val['clubId'];
                        $temp[$key]['clubName'] = $arrClubInfo ? $arrClubInfo['title'] : '';
                        $temp[$key]['image'] = $arrClubInfo ? $arrClubInfo['image'] : '';
                        $info = $this->paomeDb->getRow("select id,score_rank_num,total_score,mileage_score,speed_score,support_score from r_pm_score where contest_id=$paomeId and club_id={$val['clubId']} and `type`=$roundId");
                        $temp[$key]['rank'] = $info ? $info['score_rank_num']  : 0;
                        $temp[$key]['rankValue'] = $info ? $info['total_score'] : 0;
                        $temp[$key]['mileageScore'] = $info ? $info['mileage_score'] : 0;
                        $temp[$key]['speedScore'] =  $info ? $info['speed_score'] : 0;
                        $temp[$key]['supportScore'] = $info ? $info['support_score'] : 0;
                    }
                    $result['list'] = $temp;
                }
                break;
            default:
                return [];
                break;
        }
        return $result;
    }




    /**
     * 查询对象排名变动
     * @param $paomeId
     * @param $roundId  轮次
     * @param $objectId  对象ID  $typeWd = 1 || 5 || 10（俱乐部） $typeWd = 15（用户）
     * @param int $typeWd   维度 1 总里程 5 配速 10 人气 15 全员跑量榜
     */
    public function getObjectRankChange($paomeId, $roundId, $objectId, $typeWd=1) {
        $result =[];
        $nowTime = time();
        $yesterdayTime = time()-86400;
        $redis = $this->redis;
        switch($typeWd) {
            case 1:
                $rankClubDayKeyMile = 'rankClubDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$yesterdayTime);//昨天
                if(($rankYes = $redis->zRevRank($rankClubDayKeyMile,$objectId)) === false) {
                    return $result;
                }
                $rankClubDayKeyMile2 = 'rankClubDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//今天
                if(($rankToday = $redis->zRevRank($rankClubDayKeyMile2,$objectId)) === false) {
                    return $result;
                }
                break;
            case 5:
                $rankClubDayKeySpeed = 'rankClubDay-speed-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$yesterdayTime);//天
                if(($rankYes = $redis->zRank($rankClubDayKeySpeed,$objectId)) === false) {
                    return $result;
                }
                $rankClubDayKeySpeed2 = 'rankClubDay-speed-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天
                if(($rankToday = $redis->zRank($rankClubDayKeySpeed2,$objectId)) === false) {
                    return $result;
                }
                break;
            case 10:
                $rankClubDayKeySupportNum = 'rankClubDay-supportNum-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$yesterdayTime);//天
                if(($rankYes = $redis->zRevRank($rankClubDayKeySupportNum,$objectId)) === false) {
                    return $result;
                }
                $rankClubDayKeySupportNum2 = 'rankClubDay-supportNum-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天
                if(($rankToday = $redis->zRevRank($rankClubDayKeySupportNum2,$objectId)) === false) {
                    return $result;
                }
                break;
            case 15:
                $rankUserDayKeyMile = 'rankUserDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$yesterdayTime);//天
                if(($rankYes = $redis->zRevRank($rankUserDayKeyMile,$objectId)) === false) {
                    return $result;
                }
                $rankUserDayKeyMile2 = 'rankUserDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',$nowTime);//天
                if(($rankToday = $redis->zRevRank($rankUserDayKeyMile2,$objectId)) === false) {
                    return $result;
                }
                break;
            default:
                return [];
                break;
        }
        if (!$rankYes) {
            return $result;
        }
        $num = bcsub($rankYes,$rankToday);
        return $this->drawChangeDescForRank($num);
    }

    /**
     *  说明文字渲染
     * @param $num  变动值
     * @param int $type
     * @return array
     */
    public function drawChangeDescForRank($num) {
        $arrDesc = $this->desc;
            if ($num == 0) {
                $flag = 'RANK3';
                $desc = vsprintf($arrDesc['RANK3'],array($num));
            } elseif($num > 0) {
                $flag = 'RANK1';
                $desc = vsprintf($arrDesc['RANK1'],array($num));
            } elseif($num < 0) {
                $flag = 'RANK2';
                $desc = vsprintf($arrDesc['RANK2'],array(abs($num)));
            }
        return array('flag'=>$flag, 'num'=>$num,'desc'=>$desc);
    }

    /**
     * 排行榜 总里程淘汰俱乐部列表
     */
    public function getRankOverClub($paomeId, $roundId) {
        $arrOverClub = $this->base->load('paome/paomeClub')->getOverClubList($paomeId, $roundId);
        if (!$arrOverClub)  return [];
        $result = [];
        foreach ($arrOverClub as $key=>$val) {
            $arrCLubInfo = $this->base->load('paome/paomeClub')->getClubInfo($val['club_id'],'title,image');
            $result[$key]['clubId'] = $val['club_id'];
            $result[$key]['clubName'] = $arrCLubInfo ? $arrCLubInfo['title'] : '';
            $result[$key]['image'] = $arrCLubInfo ? $arrCLubInfo['image'] : '';
            $result[$key]['rank'] = $val['history_rank'];
            $result[$key]['rankValue'] = $val['mileage'] ;
            $result[$key]['overDesc'] = '止步预选赛';//淘汰标识文字  //名次变动说明文字数组
            $result[$key]['rankChangeInfo'] = [];
        }
        return $result;
    }

    /**
     * 用户移除或退出，全员跑量榜删除
     */
    public function delUserRank($paomeId, $uid, $clubId, $roundId, $roundId2) {
        if (!$paomeId || !$uid || !$clubId || !$roundId || !$roundId2) {
            return false;
        }
        //r_pm_rank
        $info = $this->paomeDb->getRow("select id from r_pm_rank where contest_id=$paomeId and club_id=$clubId and `type`=$roundId and type_wd=15 and object_id=$uid and status=0");
        if($info) {
            //$this->paomeDb->update("update r_pm_rank set status= -5 where id={$info['id']}");
            $this->paomeDb->delDataTable('r_pm_rank',"id={$info['id']}");//唯一索引需要，避免重复
        }
        //r_pm_rank_day
        $date = date("Ymd",time());
        $info = $this->paomeDb->getRow("select id from r_pm_rank_day where contest_id=$paomeId and club_id=$clubId and `type`=$roundId and type_wd=15 and object_id=$uid and status=0 and `date`='$date'");
        if ($info){
            //$this->paomeDb->update("update r_pm_rank_day set status= -5 where id={$info['id']}");
            $this->paomeDb->delDataTable('r_pm_rank_day',"id={$info['id']}");//唯一索引需要，避免重复

        }

        //r_pm_rank_jd
        $info = $this->paomeDb->getRow("select id from r_pm_rank_jd where contest_id=$paomeId and club_id=$clubId and `type`=$roundId2 and type_wd=15 and object_id=$uid and status=0");
        if ($info){
            //$this->paomeDb->update("update r_pm_rank_jd set status= -5 where id={$info['id']}");
            $this->paomeDb->delDataTable('r_pm_rank_jd',"id={$info['id']}");//唯一索引需要，避免重复
        }
        //删除全员跑量榜缓存
        //全员跑量
        $rankUserKeyMile = 'rankUser-mileage-'.$paomeId.'-'.$roundId;
        $rankUserDayKeyMile = 'rankUserDay-mileage-'.$paomeId.'-'.$roundId.'-'.date('Y-m-d',time());//天
        $rankUserJdKeyMile = 'rankUserJd-mileage-'.$paomeId.'-'.$roundId.'-'.$roundId2;//阶段
        $this->redis->zRem($rankUserKeyMile, $uid);
        $this->redis->zRem($rankUserDayKeyMile, $uid);
        $this->redis->zRem($rankUserJdKeyMile, $uid);
        return true;
    }

    /**
     * 争霸赛获取战队排名所匹配积分
     * @param int $rank     名次
     * @param int $typeWd   维度 1 总里程 5 配速 10 人气
     */
    public function getClubRankScore($rank, $typeWd) {
        $score = 0;
        switch($typeWd) {
            case 1:
                $rank == 1 && $score = 12;
                $rank == 2 && $score = 10;
                $rank == 3 && $score = 8;
                if($rank >= 4 && $rank <= 6){
                    $score = 6;
                }
                if($rank >= 7 && $rank <= 10){
                    $score = 4;
                }
                $rank >= 11 && $score = 2;
                break;
            case 5:
                $rank == 1 && $score = 12;
                $rank == 2 && $score = 10;
                $rank == 3 && $score = 8;
                if($rank >= 4 && $rank <= 6){
                    $score = 6;
                }
                if($rank >= 7 && $rank <= 10){
                    $score = 4;
                }
                $rank >= 11 && $score = 2;
                break;
            case 10:
                $rank == 1 && $score = 8;
                $rank == 2 && $score = 7;
                $rank == 3 && $score = 6;
                if($rank >= 4 && $rank <= 6){
                    $score = 5;
                }
                if($rank >= 7 && $rank <= 10){
                    $score = 3;
                }
                $rank >= 11 && $score = 2;
                break;
        }
        return $score;
    }
}